//
//  MeTopView.m
//  gushihui
//
//  Created by 甘世清 on 2024/1/24.
//

#import "MeTopView.h"
#import "RealViewController.h"
#import "MyVipViewController.h"
#import "FollowListViewController.h"//我的关注
#import "FangkeViewController.h"
#import "FenshiViewController.h"
#import "MyMiDouViewController.h"
@implementation MeTopView
- (void)SQ_UIViewForSelfView{
    self.backgroundColor = UIColor.clearColor;
    [self addSubview:self.avatarImage];
    [self addSubview:self.nameLabel];
    [self.avatarImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(64);
        make.left.equalTo(self).offset(22);
        make.top.equalTo(self).offset(TopHeight+20);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.avatarImage).offset(8);
        make.left.equalTo(self.avatarImage.mas_right).offset(12);
    }];
    [self addSubview:self.renzhenBtn];
    [self.renzhenBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(80);
            make.height.mas_equalTo(34);
            make.centerY.equalTo(self.nameLabel);
            make.left.equalTo(self.nameLabel.mas_right);
    }];
    [self.renzhenBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        UserModel * model = [UserModel share];
        if (model.realStatus == 2) {
            return;
        }
        RealViewController * vc = [[RealViewController alloc]init];
        [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }];
    
    [self addSubview:self.midouLabel];
    [self.midouLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(4);
    }];
    
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = UIColor.clearColor;
    [btn addTarget:self action:@selector(SQ_pushmidou) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.midouLabel).insets(UIEdgeInsetsMake(-2, -2, -2, -40));
    }];
    
    UILabel * label1 = [[UILabel alloc]init];
    label1.text = SQNSLocalString(@"关注");
    label1.textColor =  SQColor(@"#AAAAAA");
    label1.font = FONT_REGULAR(13);
    label1.textAlignment = NSTextAlignmentCenter;
    [self addSubview:label1];
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.width.mas_equalTo(SCREEN_WIDETH/3.f);
        make.top.equalTo(self.avatarImage.mas_bottom).offset(50);
    }];
    [self addSubview:self.guanzhu];
    [self.guanzhu mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(label1);
        make.top.equalTo(self.avatarImage.mas_bottom).offset(26);
    }];
    UILabel * label2 = [[UILabel alloc]init];
    label2.text = SQNSLocalString(@"粉丝");
    label2.textColor =  SQColor(@"#AAAAAA");
    label2.font = FONT_REGULAR(13);
    label2.textAlignment = NSTextAlignmentCenter;
    [self addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(label1.mas_right);
        make.width.mas_equalTo(SCREEN_WIDETH/3.f);
        make.top.equalTo(self.avatarImage.mas_bottom).offset(50);
    }];
    [self addSubview:self.fenshi];
    [self.fenshi mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(label2);
        make.top.equalTo(self.avatarImage.mas_bottom).offset(26);
    }];
    UILabel * label3 = [[UILabel alloc]init];
    label3.text = SQNSLocalString(@"访客");
    label3.textColor =  SQColor(@"#AAAAAA");
    label3.font = FONT_REGULAR(13);
    label3.textAlignment = NSTextAlignmentCenter;
    [self addSubview:label3];
    [label3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(label2.mas_right);
        make.width.mas_equalTo(SCREEN_WIDETH/3.f);
        make.top.equalTo(self.avatarImage.mas_bottom).offset(50);
    }];
    [self addSubview:self.fangke];
    [self.fangke mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(label3);
        make.top.equalTo(self.avatarImage.mas_bottom).offset(26);
    }];
    
    UIView * lineView = [[UIView alloc]init];
    lineView.backgroundColor = UIColor.whiteColor;
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(24);
        make.left.equalTo(label2).offset(-1);
        make.top.equalTo(label2).offset(-12);
    }];
    UIView * lineView2 = [[UIView alloc]init];
    lineView2.backgroundColor = UIColor.whiteColor;
    [self addSubview:lineView2];
    [lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(24);
        make.left.equalTo(label3).offset(-1);
        make.top.equalTo(label2).offset(-12);
    }];
    
    UIButton * btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn1.backgroundColor = UIColor.clearColor;
    [btn1 addTarget:self action:@selector(SQ_pushguanzhu) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn1];
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(label1);
        make.top.equalTo(self.guanzhu);
    }];
    
    UIButton * btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn2.backgroundColor = UIColor.clearColor;
    [btn2 addTarget:self action:@selector(SQ_pushfenshi) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn2];
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(label2);
        make.top.equalTo(self.guanzhu);
    }];
    
    UIButton * btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn3.backgroundColor = UIColor.clearColor;
    [btn3 addTarget:self action:@selector(SQ_pushFangke) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn3];
    [btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(label3);
        make.top.equalTo(self.guanzhu);
    }];
    
    
    [self addSubview:self.VipImage];
    [self.VipImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
        make.width.mas_equalTo(SCREEN_WIDETH-32);
        make.height.mas_equalTo(84);
        make.top.equalTo(self.avatarImage.mas_bottom).offset(95);
    }];
    UILabel * label4 = [[UILabel alloc]init];
    label4.text = SQNSLocalString(@"Vip状态");
    label4.textColor =  SQColorF4F4F4;
    label4.font = FONT_MEDIUM(15);
    [self.VipImage addSubview:label4];
    [label4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.VipImage).offset(24);
        make.top.equalTo(self.VipImage).offset(23);
    }];

    [self.VipImage addSubview:self.zhuangtai];
    [self.zhuangtai mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(label4);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(24);
        make.left.equalTo(label4.mas_right).offset(4);
    }];
    [self.VipImage addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.VipImage).offset(24);
        make.top.equalTo(self.VipImage).offset(46);
    }];
 
}
- (void)SQ_setdata{
    UserModel * model = [UserModel share];
    _midouLabel.text = [NSString stringWithFormat:@"%@%d",SQNSLocalString(@"觅豆:"),model.diamond];
    [self.avatarImage.headerImage sd_setImageWithURL:SQURLImage(model.portrait) placeholderImage:SQGetImage(@"zanwutouxiang")];
    self.nameLabel.text = model.name;
    self.fenshi.text = model.fenCount;
    self.guanzhu.text = model.attentionCount;
    self.fangke.text = model.visitorCount;
    
    if (model.realStatus == 2) {
        self.renzhenBtn.text = SQNSLocalString(@"已认证");
        _renzhenBtn.image = SQGetImage(@"认证");
    } else if(model.realStatus == 0) {
        self.renzhenBtn.text = SQNSLocalString(@"审核中");
        _renzhenBtn.image = SQGetImage(@"未认证");
    }else {
        self.renzhenBtn.text = SQNSLocalString(@"未认证");
        _renzhenBtn.image = SQGetImage(@"未认证");
    }
    if (model.isVip) {
        self.VipImage.image = @"VIP 已开通";
        self.zhuangtai.text = SQNSLocalString(@"已开通");
        self.timeLabel.text = model.endTime;
    } else {
        self.VipImage.image = @"VIP 未开通";
        self.zhuangtai.text = SQNSLocalString(@"未开通");
        self.timeLabel.hidden = YES;
    }
}
-(void)SQ_PushPeople{
    PeopleDetailViewController * vc = [[PeopleDetailViewController alloc]init];
    vc.uid = [UserModel share].userid;
    [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
}
-(void)SQ_PushVip{
    MyVipViewController * vc = [[MyVipViewController alloc]init];
    [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
}
-(void)SQ_pushmidou{
    MyMiDouViewController * vc = [[MyMiDouViewController alloc]init];
    [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
}
-(void)SQ_pushguanzhu{
    FollowListViewController* vc = [[FollowListViewController alloc]init];
    [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
}
-(void)SQ_pushfenshi{
    FenshiViewController* vc = [[FenshiViewController alloc]init];
    [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
}
-(void)SQ_pushFangke{
    FangkeViewController* vc = [[FangkeViewController alloc]init];
    [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
}
- (HeaderView *)avatarImage{
    if (!_avatarImage) {
        _avatarImage = [[HeaderView alloc]init];
        _avatarImage.headerImage.contentMode = UIViewContentModeScaleAspectFill;
        _avatarImage.clipsToBounds = YES;
        _avatarImage.layer.cornerRadius = 32;
        _avatarImage.layer.borderColor = UIColor.whiteColor.CGColor;
        _avatarImage.layer.borderWidth = 1;
        [_avatarImage.btn addTarget:self action:@selector(SQ_PushPeople) forControlEvents:UIControlEventTouchUpInside];
        _avatarImage.headerImage.image = SQGetImage(@"zanwutouxiang");
    }
    return _avatarImage;
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = FONT_SEMIBOLD(18);
        _nameLabel.textColor = UIColor.whiteColor;
    }
    return _nameLabel;
}

- (SQCustomButton *)renzhenBtn{
    if (!_renzhenBtn) {
        _renzhenBtn = [[SQCustomButton alloc]initType:SQCustomButtonLeftImageType imageSize:CGSizeMake(22, 22) midmargin:4];
        _renzhenBtn.image = SQGetImage(@"认证");
        _renzhenBtn.font = FONT_MEDIUM(14);
        _renzhenBtn.textColor = UIColor.whiteColor;
    }
    return _renzhenBtn;
}
- (UILabel *)midouLabel{
    if (!_midouLabel) {
        _midouLabel = [[UILabel alloc]init];
        _midouLabel.textColor = SQColor(@"#FFDC3D");
        _midouLabel.font = FONT_REGULAR(14);
       
    }
    return _midouLabel;
}
- (UILabel *)fenshi{
    if (!_fenshi) {
        _fenshi = [[UILabel alloc]init];
        _fenshi.textColor = UIColor.whiteColor;
        _fenshi.text = SQNSLocalString(@"0");
        _fenshi.textAlignment = NSTextAlignmentCenter;
        _fenshi.font = FONT_SEMIBOLD(18);
        
    }
    return _fenshi;
}
- (UILabel *)guanzhu{
    if (!_guanzhu) {
        _guanzhu = [[UILabel alloc]init];
        _guanzhu.textColor = UIColor.whiteColor;
        _guanzhu.text = SQNSLocalString(@"0");
        _guanzhu.textAlignment = NSTextAlignmentCenter;
        _guanzhu.font = FONT_SEMIBOLD(18);
    }
    return _guanzhu;
}
- (UILabel *)fangke{
    if (!_fangke) {
        _fangke = [[UILabel alloc]init];
        _fangke.textColor = UIColor.whiteColor;
        _fangke.text = SQNSLocalString(@"0");
        _fangke.textAlignment = NSTextAlignmentCenter;
        _fangke.font = FONT_SEMIBOLD(18);
    }
    return _fangke;
}
- (UILabel *)zhuangtai{
    if (!_zhuangtai) {
        _zhuangtai = [[UILabel alloc]init];
        _zhuangtai.textColor =SQColorF4F4F4;
        _zhuangtai.font = FONT_REGULAR(13);
        _zhuangtai.text = SQNSLocalString(@"未开通");
        _zhuangtai.backgroundColor = UIColor.blackColor;
        _zhuangtai.layer.cornerRadius = 12;
        _zhuangtai.textAlignment = NSTextAlignmentCenter;
        _zhuangtai.layer.masksToBounds = YES;
    }
    return _zhuangtai;
}
- (HeaderView *)VipImage{
    if (!_VipImage) {
        _VipImage = [[HeaderView alloc]init];
        _VipImage.image = @"VIP 未开通";
        [_VipImage.btn addTarget:self action:@selector(SQ_PushVip) forControlEvents:UIControlEventTouchUpInside];
    }
    return _VipImage;
}
- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.font = FONT_REGULAR(13);
        _timeLabel.textColor = UIColor.whiteColor;
    }
    return _timeLabel;
}
@end
